package com.lab.account.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.common.dao.GenericDao;
import com.common.service.GenericManagerImpl;
import com.common.service.ServiceException;
import com.lab.account.domain.Role;
import com.lab.account.domain.User;

@Service(value = "roleManager")
public class RoleManagerImpl extends GenericManagerImpl<Role, Long> implements
		RoleManager {

	private GenericDao<Role, Long> roleDao;

	@Autowired
	public RoleManagerImpl(@Qualifier("roleDao")
	GenericDao<Role, Long> roleDao) {
		super(roleDao);
		this.roleDao = roleDao;
	}

	@Override
	public void remove(Long id) throws ServiceException {
		Role role = get(id);
		for (User user : role.getUserList()) {
			user.getRoleList().remove(role);
		}

		super.remove(id);
	}

}
